<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="提交申请" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <!-- 标题栏 -->
        <view class="head-box">
            <view class="head-img-wrap">
                <image class="head-img" :src="$globalConstVars.apiFilesUrl + '/static/images/agent/applyBg.jpg'" mode="widthFix"></image>
            </view>
        </view>
        <!-- 表单 -->
        <view class="coreshop-bg-white coreshop-border-radius-10 coreshop-padding-15 coreshop-margin-10">
            <view class="u-content">
                <u-parse :content="agentAgreement" :selectable="true"></u-parse>
            </view>

        </view>

        <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
            <u-button type="primary" size="normal" @click="submit()">申请成为代理商</u-button>
        </view>

    </view>
</template>
<script>
    import { mapState } from 'vuex';
    export default {
        data() {
            return {
                form: {
                    name: '',
                    weixin: '',
                    qq: '',
                    mobile: '',
                }
            }
        },
        computed: {
            ...mapState({
                hasLogin: state => state.hasLogin,
                userInfo: state => state.userInfo,
            }),
            agentAgreement() {
                return this.$store.state.config.agentAgreement
            },
            userInfo: {
                get() {
                    return this.$store.state.userInfo;
                },
                set(val) {
                    this.$store.commit('userInfo', val);
                }
            },
        },
        methods: {
            submit() {
                // 提交审核
                let data = {
                    name: this.userInfo.nickName,
                    weixin: this.userInfo.mobile,
                    qq: this.userInfo.mobile,
                    mobile: this.userInfo.mobile,
                    agreement: "on",
                }
                this.$u.api.applyAgent(data).then(res => {
                    if (res.status) {
                        this.$refs.uToast.show({ message: res.msg, type: 'success', url: '/pages/member/agent/applyState/applyState' })
                    } else {
                        this.$u.toast(res.msg);
                    }
                });

            },
            goAgreement() {
                uni.navigateTo({
                    url: '/pages/member/agent/agreement/agreement'
                })
            }
        }
    }
</script>
<style lang="scss" scoped>
    @import 'apply.scss';
</style>
